home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_496 / memmometer / mm.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  39KB  |  1,204 lines

  1. /* : ai=0 bk=0 ts=8 */
  2. #include "mm.h"
  3.  
  4. #define FREEPEN -1L           /* workbench screen default colors */
  5. #define REQ_WINDOW_WIDTH 319L /* width of warning requester window */
  6. #define REQ_WINDOW_HEIGHT 79L /* height of warning requester window */
  7.  
  8. #define SOK        0x001f     /* memory allocation control masks */
  9. #define S1         0x0001
  10. #define S2         0x0002
  11. #define S4         0x0004
  12. #define S8         0x0008
  13. #define SA         0x0010
  14. #define C1         0xfffe
  15. #define C2         0xfffd
  16. #define C4         0xfffb
  17. #define C8         0xfff7
  18. #define CA         0xffef
  19. #define AARRRGH    20L         /* hang 20, cats, we're startin ta curl! */
  20.  
  21. #define EXTENSION  16L         /* allocation request increment */
  22.  
  23. #define FRAGS FALSE                          /* frags mode control boolian */
  24. #define WARPS TRUE                           /* warps mode control boolian */
  25. #define EVENMASK 0x7ffffffe           /* used to prevent odd address traps */
  26. #define CLIHEIGHT 200L                             /* window scaling stuff */
  27. #define SIZEGAD 9L
  28. #define DRAGBAR 10L
  29. #define BORDER 2L
  30. #define WINW 16L                                   /* initial window width */
  31. #define WINH (long)(CLIHEIGHT - SIZEGAD - DRAGBAR)   /* initial win height */
  32. #define MINH 81L                              /* shortest allowable window */
  33. #define MAXH 576L                              /* longest allowable window */
  34. #define BART 1L                               /* title bar F text location */
  35. #define BARH (long)(WINH - SIZEGAD - DRAGBAR)                /* bar height */
  36. #define BARS (long)(BARH + 1)        /* number of memory items to allocate */
  37. #define BARB (long)(BARH + DRAGBAR - 1)        /* bottom of mercury column */
  38. #define BARE (long)(BARB + BORDER)              /* bar end E text position */
  39. #define BARW (long)(((WINW - (2 * BORDER)) / 3) - 1)  /* 3 memfragmometers */
  40. #define LEFT BORDER                   /* SLOW : since we're syncopated, we */
  41. #define MIDDLE (LEFT + BARW + 1)      /* SLOW-FAST : do it going from bar  */
  42. #define RIGHT (MIDDLE + BARW + 1)     /* FAST :to bar at an irregular pace */
  43. #define RTEXT - 4L        /* offset for three char E/F text from left edge */
  44. #define STARTVAL 64L    /* start by getting enough storage for a few frags */
  45. #define TMARK 100000L                     /* timer granule in microseconds */
  46. #define TICKIES (long)(1000000/TMARK)       /* number of TMARKS per second */
  47.  
  48. /* typedef short BOOL */        /* this is in include/exec/types.h */
  49.  
  50. struct IntuitionBase *IntuitionBase=NULL ;
  51. struct Window *window ;
  52. struct IntuiMessage *message;
  53. /* struct IntuiMessage *GetMsg(); */        /* in functions.h */
  54.  
  55. struct GfxBase *GfxBase=NULL ;
  56.  
  57. struct IOStdReq *timermsg=NULL;
  58. struct MsgPort *timerport=NULL;
  59. ULONG  timerbit=NULL;
  60.  
  61.  
  62. extern void InitProjItems();        /* this stuff is in the mminit section */
  63. extern void InitSetupItems();
  64. extern void InitPrioItems();
  65. extern void InitChipItems();
  66. extern void InitChipAItems();
  67. extern void InitSFItems();
  68. extern void InitSFAItems();
  69. extern void InitFastItems();
  70. extern void InitFastAItems();
  71. extern void InitMenu();
  72. extern void StartMenus();
  73.  
  74. BOOL p_mode = FRAGS;          /* preset frags mode = 0, warps mode = 1 */
  75.                               /* note: mode preset used as request for */
  76.                               /*       change to warps mode after the  */
  77.                               /*       first pass with frags mode set! */
  78. long p_rate = 2;              /* preset sample interval, secs see menu */
  79. long p_priority = 0;          /* preset priority, range -128 to +127   */
  80.                               /* note: pri greater than zero is risky! */
  81.                               /* keep in mind AmigaDOS priorities:     */
  82.                               /* input.device 20, FileSystem 10, and   */
  83.                               /* trackdisk.device, CON: 5 also if MM   */
  84.                               /* is started from a CLI without the Run */
  85.                               /* then that CLI inherits MM's priority! */
  86. long p_chip = 512;            /* preset chip mem size, kbytes see menu */
  87. long p_chipa = 0;             /* preset chip mem address, kb  see menu */
  88. long p_sf = 0;                /* preset slowfast mem size, kb see menu */
  89. long p_sfa = 2048;            /* preset slowfast mem addr, kb see menu */
  90. long p_fast = 0;              /* preset fast mem size, mbytes see menu */
  91. long p_fasta = -1;            /* preset fast mem addr, mbytes see menu */
  92.                               /* zero or neg fasta is offset below the */
  93.                               /* A3000 fast ram ceiling, aka 0x7000000 */
  94.  
  95. static BOOL mode;                    /* uninitialized for mode control */
  96. static BOOL mmode;                   /* uninitialized for mode  menu */
  97. static long delayval;                /* uninitialized for delay menu */
  98. static long priority;                /* uninitialized for priority menu */
  99. static long lastpri;                 /* uninitialized for priority incr */
  100. static long cmemsize;                /* uninitialized for chip  menu */
  101. static long cmembase;                /* uninitialized for chipa menu */
  102. static long sfmemsize;               /* uninitialized for sf    menu */
  103. static long sfmembase;               /* uninitialized for sfa   menu */
  104. static long fmemsize;                /* uninitialized for fast  menu */
  105. static long fmembase;                /* uninitialized for fasta menu */
  106.  
  107. static USHORT log ;                  /* memory allocation success flags */
  108. static BOOL things_are_cool = TRUE ; /* tells when to close the window  */
  109. static BOOL intsig = FALSE ;         /* intuition message detector */
  110. static USHORT chgflag = TRUE ;       /* menu request to adjust columns */
  111. static long chip[3], fast[3] ;       /* place to keep mem header pointers */
  112. static ULONG  *chunkv ;              /* demand allocated for frag chunks */
  113. static ULONG  *sizev ;               /* demand allocated for frag sizes */
  114. static ULONG  *csum ;                /* a col's height worth of checksums */
  115. static ULONG  *oldcsum ;             /* same height worth of old checksums */
  116. static USHORT *cell;                 /* 1 cell per pixel height of mercury */
  117. static long xl, xr ;                 /* used to Draw() memmometer segments */
  118. static long frags = STARTVAL ;       /* # of demand allocated frag items */
  119. static long warps = BARS ;           /* # of demand allocated column items */
  120. static long barh = BARH ;            /* EVEN #'d height of mercury column */
  121. static long barb = BARB ;            /* bottom position of mercury column */
  122. static short ticker = TICKIES ;      /* initialized delay tick variable */
  123.  
  124. /* struct RastPort *rp ; */          /* wonder why we don't need this... ? */
  125.  
  126.  
  127. static struct TextAttr myfont = {
  128.    (STRPTR) "topaz.font",
  129.    TOPAZ_EIGHTY,
  130.    0,
  131.    0
  132. };
  133. /* E newsize gadget refresh text */ 
  134. static char ebuf[4] = " E " ;
  135. static struct IntuiText e_text = { 
  136.    BLUP, WHTP,
  137.    JAM2, 
  138.    0, BARE,
  139.    &myfont,
  140.    (UBYTE *)ebuf, 
  141.    NULL 
  142. };
  143. /* F title refresh text */
  144. static char fbuf[4] = " F " ;
  145. static struct IntuiText f_text = {
  146.    BLUP, WHTP,
  147.    JAM2,
  148.    0, BART,
  149.    &myfont,
  150.    (UBYTE *)fbuf,
  151.    &e_text
  152. };
  153. static struct NewWindow newwindow = {
  154.    0,                                        /* left edge */
  155.    10,                                       /* top edge */
  156.    WINW,                                     /* width */
  157.    WINH,                                     /* height */
  158.    0,                                        /* detail pen */
  159.    1,                                        /* block pen */
  160.    MENUPICK | NEWSIZE,                       /* messages */
  161. /* WINDOWDEPTH | WINDOWCLOSE */              /* don't use these gads */
  162.    WINDOWDRAG | WINDOWSIZING | NOCAREREFRESH,   /* add a few gadgets */
  163.    NULL,                                     /* no custom gadgets */
  164.    NULL,                                     /* default checkmark */
  165.    (UBYTE *)"F",                             /* title */
  166.    NULL,                                     /* initialize this! */
  167.    NULL,                                     /* use screen bitmap */
  168.    WINW, MINH, WINW, MAXH,                   /* min and max sizes */
  169.    WBENCHSCREEN } ;                          /* use workbench screen */
  170.  
  171. void initmenus()
  172. {
  173.    (void) InitProjItems();              /* Initialize the menu items */
  174.    (void) InitSetupItems();
  175.    (void) InitPrioItems();
  176.    (void) InitChipItems();
  177.    (void) InitChipAItems();
  178.    (void) InitSFItems();
  179.    (void) InitSFAItems();
  180.    (void) InitFastItems();
  181.    (void) InitFastAItems();
  182.    (void) InitMenu();
  183.    (void) StartMenus();
  184.    }
  185.  
  186. void handle_MENUPICK( class, code )
  187. unsigned long class;
  188. unsigned int code;
  189. {
  190.     unsigned int menunum, itemnum, subnum;
  191.  
  192.     if (code == MENUNULL) return;
  193.  
  194.     menunum = MENUNUM( code );
  195.     itemnum = ITEMNUM( code );
  196.     subnum  = SUBNUM( code );
  197.     chgflag = TRUE;
  198.     switch( menunum ) {
  199.         case 0:
  200.         switch( itemnum ) {
  201.             case 0:
  202.             WindowToFront(window);
  203.             break;
  204.  
  205.             case 1:
  206.             WindowToBack(window);
  207.             break;
  208.  
  209.             case 2:
  210.             things_are_cool = FALSE;  /* Quit */
  211.             break;
  212.             } /* end of switch ( Project itemnum ) */
  213.         break;
  214.  
  215.         case 1:
  216.         switch( itemnum ) {
  217.             case 0:
  218.             switch( subnum ) {
  219.                 case 0:
  220.                 mode = FRAGS ;  /* Frags mode */
  221.                 break;
  222.  
  223.                 case 1:
  224.                 mmode = TRUE ;  /* Warps request */
  225.                 break;
  226.                 /* end of switch ( Mode subnum ) */
  227.                 }
  228.             break;       
  229.             case 1:
  230.             switch( subnum ) {
  231.                 case 0:
  232.                 delayval = 1;
  233.                 break;
  234.  
  235.                 case 1:
  236.                 delayval = 2;
  237.                 break;
  238.  
  239.                 case 2:
  240.                 delayval = 5;
  241.                 break;
  242.  
  243.                 case 3:
  244.                 delayval = 10;
  245.                 break;
  246.                 /* end of switch ( Freq subnum ) */
  247.                 }
  248.             break;       
  249.             /* end of switch ( Setup itemnum ) */
  250.             }
  251.         break;
  252.  
  253.         case 2:
  254.         switch( itemnum ) {
  255.             case  0:
  256.             priority = lastpri;
  257.             break;
  258.  
  259.             case  1:
  260.             priority = priority - 1;
  261.             break;
  262.  
  263.             case  2:
  264.             priority = priority + 1;
  265.             break;
  266.  
  267.             case  3:
  268.             priority = -99;
  269.             lastpri = priority;
  270.             break;
  271.  
  272.             case  4:
  273.             priority = -75;
  274.             lastpri = priority;
  275.             break;
  276.  
  277.             case  5:
  278.             priority = -50;
  279.             lastpri = priority;
  280.             break;
  281.  
  282.             case  6:
  283.             priority = -25;
  284.             lastpri = priority;
  285.             break;
  286.  
  287.             case  7:
  288.             priority = -20;
  289.             lastpri = priority;
  290.             break;
  291.  
  292.             case  8:
  293.             priority = -15;
  294.             lastpri = priority;
  295.             break;
  296.  
  297.             case  9:
  298.             priority = -10;
  299.             lastpri = priority;
  300.             break;
  301.  
  302.             case 10:
  303.             priority =  -5;
  304.             lastpri = priority;
  305.             break;
  306.  
  307.             case 11:
  308.             priority =   0;
  309.             lastpri = priority;
  310.             break;
  311.  
  312.             case 12:
  313.             priority =   5;
  314.             lastpri = priority;
  315.             break;
  316.  
  317.             case 13:
  318.             priority =  10;
  319.             lastpri = priority;
  320.             break;
  321.  
  322.             case 14:
  323.             priority =  15;
  324.             lastpri = priority;
  325.             break;
  326.  
  327.             case 15:
  328.             priority =  20;
  329.             lastpri = priority;
  330.             break;
  331.             }
  332.             /* end of switch ( Priority itemnum ) */
  333.         break;
  334.  
  335.         case 3:
  336.         switch( itemnum ) {
  337.             case 0:
  338.             cmemsize = 0x000000;
  339.             break;
  340.  
  341.             case 1:
  342.             cmemsize = 0x040000;
  343.             break;
  344.  
  345.             case 2:
  346.             cmemsize = 0x080000;
  347.             break;
  348.  
  349.             case 3:
  350.             cmemsize = 0x100000;
  351.             break;
  352.  
  353.             case 4:
  354.             cmemsize = 0x200000;
  355.             break;
  356.             }
  357.             /* end of switch ( Chip Size itemnum ) */
  358.         break;
  359.  
  360.         case 4:
  361.         switch( itemnum ) {
  362.             case 0:
  363.             cmembase = 0x000000;
  364.             break;
  365.  
  366.             case 1:
  367.             cmembase = 0x040000;
  368.             break;
  369.  
  370.             case 2:
  371.             cmembase = 0x080000;
  372.             break;
  373.  
  374.             case 3:
  375.             cmembase = 0x100000;
  376.             break;
  377.             }
  378.             /* end of switch ( Chip Addr itemnum ) */
  379.         break;
  380.  
  381.         case 5:
  382.         if (mode == WARPS)  mmode = TRUE ;
  383.         switch( itemnum ) {
  384.             case 0:
  385.             sfmemsize = 0x000000;
  386.             break;
  387.  
  388.             case 1:
  389.             sfmemsize = 0x040000;
  390.             break;
  391.  
  392.             case 2:
  393.             sfmemsize = 0x080000;
  394.             break;
  395.  
  396.             case 3:
  397.             sfmemsize = 0x0C0000;
  398.             break;
  399.  
  400.             case 4:
  401.             sfmemsize = 0x100000;
  402.             break;
  403.  
  404.             case 5:
  405.             sfmemsize = 0x180000;
  406.             break;
  407.  
  408.             case 6:
  409.             sfmemsize = 0x200000;
  410.             break;
  411.  
  412.             case 7:
  413.             sfmemsize = 0x300000;
  414.             break;
  415.  
  416.             case 8:
  417.             sfmemsize = 0x400000;
  418.             break;
  419.  
  420.             case 9:
  421.             sfmemsize = 0x600000;
  422.             break;
  423.  
  424.             case 10:
  425.             sfmemsize = 0x800000;
  426.             break;
  427.             }
  428.             /* end of switch ( SF Size itemnum ) */
  429.         break;
  430.  
  431.         case 6:
  432.         if (mode == WARPS)  mmode = TRUE ;
  433.         switch( itemnum ) {
  434.             case 0:
  435.             sfmembase = 0x200000;
  436.             break;
  437.  
  438.             case 1:
  439.             sfmembase = 0x240000;
  440.             break;
  441.  
  442.             case 2:
  443.             sfmembase = 0x280000;
  444.             break;
  445.  
  446.             case 3:
  447.             sfmembase = 0x2C0000;
  448.             break;
  449.  
  450.             case 4:
  451.             sfmembase = 0x300000;
  452.             break;
  453.  
  454.             case 5:
  455.             sfmembase = 0x400000;
  456.             break;
  457.  
  458.             case 6:
  459.             sfmembase = 0x500000;
  460.             break;
  461.  
  462.             case 7:
  463.             sfmembase = 0x600000;
  464.             break;
  465.  
  466.             case 8:
  467.             sfmembase = 0x700000;
  468.             break;
  469.  
  470.             case 9:
  471.             sfmembase = 0x800000;
  472.             break;
  473.  
  474.             case 10:
  475.             sfmembase = 0x900000;
  476.             break;
  477.  
  478.             case 11:
  479.             sfmembase = 0xC00000;
  480.             break;
  481.  
  482.             case 12:
  483.             sfmembase = 0xC40000;
  484.             break;
  485.  
  486.             case 13:
  487.             sfmembase = 0xC80000;
  488.             break;
  489.  
  490.             case 14:
  491.             sfmembase = 0xCC0000;
  492.             break;
  493.  
  494.             case 15:
  495.             sfmembase = 0xD00000;
  496.             break;
  497.             }
  498.             /* end of switch ( SF Addr itemnum ) */
  499.         break;
  500.  
  501.         case 7:
  502.         if (mode == WARPS)  mmode = TRUE ;
  503.         switch( itemnum ) {
  504.             case 0:
  505.             fmemsize = 0x000000;
  506.             break;
  507.  
  508.             case 1:
  509.             fmemsize = 0x040000;
  510.             break;
  511.  
  512.             case 2:
  513.             fmemsize = 0x080000;
  514.             break;
  515.  
  516.             case 3:
  517.             fmemsize = 0x0C0000;
  518.             break;
  519.  
  520.             case 4:
  521.             fmemsize = 0x100000;
  522.             break;
  523.  
  524.             case 5:
  525.             fmemsize = 0x200000;
  526.             break;
  527.  
  528.             case 6:
  529.             fmemsize = 0x300000;
  530.             break;
  531.  
  532.             case 7:
  533.             fmemsize = 0x400000;
  534.             break;
  535.  
  536.             case 8:
  537.             fmemsize = 0x600000;
  538.             break;
  539.  
  540.             case 9:
  541.             fmemsize = 0x800000;
  542.             break;
  543.  
  544.             case 10:
  545.             fmemsize = 0xa000000;
  546.             break;
  547.  
  548.             case 11:
  549.             fmemsize = 0xc00000;
  550.             break;
  551.  
  552.             case 12:
  553.             fmemsize = 0xd00000;
  554.             break;
  555.  
  556.             case 13:
  557.             fmemsize = 0xe00000;
  558.             break;
  559.  
  560.             case 14:
  561.             fmemsize = 0xf00000;
  562.             break;
  563.  
  564.             case 15:
  565.             fmemsize = 0x1000000;
  566.             break;
  567.             }
  568.             /* end of switch ( Fast Size itemnum ) */
  569.         break;
  570.  
  571.         case 8:
  572.         if (mode == WARPS)  mmode = TRUE ;
  573.         switch( itemnum ) {
  574.             case 0:
  575.             fmembase = 0x200000;
  576.             break;
  577.  
  578.             case 1:
  579.             fmembase = 0x300000;
  580.             break;
  581.  
  582.             case 2:
  583.             fmembase = 0x400000;
  584.             break;
  585.  
  586.             case 3:
  587.             fmembase = 0x500000;
  588.             break;
  589.  
  590.             case 4:
  591.             fmembase = 0x600000;
  592.             break;
  593.  
  594.             case 5:
  595.             fmembase = 0x800000;
  596.             break;
  597.  
  598.             case 6:
  599.             fmembase = 0x7f0000;
  600.             break;
  601.  
  602.             case 7:
  603.             fmembase = 0x7e0000;
  604.             break;
  605.  
  606.             case 8:
  607.             fmembase = 0x7d00000;
  608.             break;
  609.  
  610.             case 9:
  611.             fmembase = 0x7c00000;
  612.             break;
  613.  
  614.             case 10:
  615.             fmembase = 0x7a00000;
  616.             break;
  617.  
  618.             case 11:
  619.             fmembase = 0x7800000;
  620.             break;
  621.  
  622.             case 12:
  623.             fmembase = 0x7600000;
  624.             break;
  625.  
  626.             case 13:
  627.             fmembase = 0x7400000;
  628.             break;
  629.  
  630.             case 14:
  631.             fmembase = 0x7200000;
  632.             break;
  633.  
  634.             case 15:
  635.             fmembase = 0x7000000;
  636.             break;
  637.             }
  638.             /* end of switch ( Fast Addr itemnum ) */
  639.         break;
  640.         }
  641.         /* end of switch ( menunum ) */
  642. }
  643.  
  644. void wrack_sploot() /* this subprogram cashes in the chips in bad times */
  645.     {
  646.     if (log != 0) {
  647.         if (log & SA) {
  648.             (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
  649.             log = log & CA ;
  650.             }
  651.         if (log & S8) {
  652.             (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
  653.             log = log & C8 ;
  654.             }
  655.         if (log & S4)  {
  656.             (void) FreeMem(sizev, (long)(sizeof(long) * frags)) ;
  657.             log = log & C4 ;
  658.             }
  659.         if (log & S2)  {
  660.             (void) FreeMem(chunkv, (long)(sizeof(long) * frags)) ;
  661.             log = log & C2 ;
  662.             }
  663.         if (log & S1) {
  664.             (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
  665.             log = log & C1 ;
  666.             }
  667.         frags = 0;
  668.         warps = 0;
  669.         }
  670. }
  671.  
  672. SetTimer(sec, micro, timermsg)
  673. ULONG sec, micro;
  674. struct IOStdReq *timermsg;
  675. /* This routine simply sets the timer to interrupt us after secs.micros */
  676. {
  677.     timermsg->io_Command = TR_ADDREQUEST;    /* add a new timer request */
  678.     timermsg->io_Actual = sec;    /* seconds */
  679.     timermsg->io_Length = micro;    /* microseconds */
  680.     SendIO(timermsg);   /* post a request to the timer */
  681. }
  682.  
  683. void cleanup() {
  684.     if (timerport) {
  685.         Wait(timerbit);
  686.         GetMsg(timerport);
  687.         CloseDevice(timermsg);
  688.         DeleteStdIO(timermsg);
  689.         DeletePort(timerport);
  690.         }
  691.     if (GfxBase)        CloseLibrary(GfxBase) ;
  692.     if (window)         CloseWindow(window) ;
  693.     if (IntuitionBase)  CloseLibrary(IntuitionBase) ;
  694.     wrack_sploot() ;
  695.     exit(AARRRGH) ;
  696. }
  697.  
  698. void inittimer() {
  699.     if(!(timerport = (struct MsgPort *)CreatePort(0L, 0L)))cleanup();
  700.     if(!(timermsg = (struct IOStdReq *)CreateStdIO(timerport)))cleanup();
  701.     if (OpenDevice(TIMERNAME, UNIT_VBLANK, timermsg, 0L))cleanup();
  702.  
  703.     timerbit = 1L << timerport->mp_SigBit ;
  704.     SetTimer(1L, 0L, timermsg); /* set for first message */
  705. }
  706.  
  707. void handle_NEWSIZE() /* short term allocations cashed in then realloc'd */
  708.     {                 /* when user hits gadget but doesn't resize window */
  709.     if (log & SA)  {
  710.         (void) FreeMem(oldcsum, (long)(sizeof(ULONG) * warps)) ;
  711.         log = log & CA ;
  712.         }
  713.     if (log & S8)  {
  714.         (void) FreeMem(csum, (long)(sizeof(ULONG) * warps)) ;
  715.         log = log & C8 ;
  716.         }
  717.     if (log & S1)  {
  718.         (void) FreeMem(cell, (long)(sizeof(USHORT) * warps)) ;
  719.         log = log & C1 ;
  720.     barh = window->Height - SIZEGAD - DRAGBAR ;  /* recalculate height */
  721.     barb = window->Height - SIZEGAD - 1 ; /* get new bar base position */
  722.     warps = barh + 1 ;       /* number of storage cells to be reserved */
  723.     if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * warps,
  724.                                     MEMF_PUBLIC)) != 0L ) log = log | S1;
  725.     if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
  726.                                     MEMF_PUBLIC)) != 0L ) log = log | S8;
  727.     if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * warps,
  728.                                     MEMF_PUBLIC)) != 0L ) log = log | SA;
  729.     if (log != SOK)  {      /* bail out if we didn't get an allocation */
  730.         wrack_sploot() ;
  731.         things_are_cool = FALSE ;     /* tell _main that we're leaving */
  732.         }
  733.     e_text.TopEdge = barb + BORDER ;        /* set the E text position */
  734.     intsig = FALSE ;
  735.     }
  736. }
  737.  
  738. void handle_MESSAGES()  {
  739.     unsigned long class;
  740.     unsigned int code, qual;
  741.  
  742.     /* Wait (1L << window->UserPort->mp_SigBit); this is rediculous! */
  743.     while ((message=(struct IntuiMessage *)GetMsg(window->UserPort))
  744.                                                                 != 0L) {
  745.         class = message->Class ;
  746.         code = message->Code ;
  747.         qual = message->Qualifier ;
  748.         ReplyMsg ;
  749.         ticker = 0 ;        /* cut short the timer to expedite service */
  750.         switch( class ) {
  751.             case MENUPICK:
  752.             handle_MENUPICK( class, code ) ;    /* do menus ASAP */
  753.             break ;
  754.  
  755.             case NEWSIZE:
  756.             intsig = TRUE ;                     /* resize when done here */
  757.             break ;
  758.             }
  759.         }
  760. }
  761.  
  762. void memmometer()                /* this subprogram draws the bar graphs */
  763.     {
  764.     long i;
  765.     long y;
  766.  
  767.     (void) handle_MESSAGES() ;  /* go see if the user wants anything */
  768.     i = 0 ;
  769.     while ((i < barh) && (intsig == FALSE)) {
  770.         y = barb - i ;
  771.         SetAPen(window->RPort, (long)cell[i]);
  772.         Move(window->RPort, xl, y);
  773.         Draw(window->RPort, xr, y);
  774.         i++ ;
  775.         }
  776. }
  777.  
  778. void shake()    /* this subprogram slings down the mercury column */
  779.     {
  780.     int i;
  781.  
  782.     for (i = 0; i < barh; i++)  {
  783.         cell[i] = YELP ;
  784.         }
  785. }
  786.  
  787. void lockout()  /* this subprogram renders a whole column in border colors */
  788.     {
  789.     (void) handle_MESSAGES() ;        /* go see if the user wants anything */
  790.     if (intsig == FALSE)  {
  791.         SetAPen(window->RPort, WHTP) ;          /* set in the border color */
  792.         RectFill(window->RPort, xl, (barb - barh + 1), xr, barb) ; /* fill */
  793.         }
  794. }
  795.  
  796. void updatewarps( wf, membase, memseg )  /* this subprogram finds changes */
  797. short wf;
  798. long membase, memseg ;
  799.     {
  800.     register long i ;
  801.     register ULONG r ;
  802.     register ULONG delta ;
  803.     register ULONG *a ;
  804.  
  805.     if (memseg == 0) {
  806.         (void) lockout() ;
  807.         return ;
  808.         }
  809.     else (void) shake() ;
  810.  
  811.     delta = (ULONG)(memseg & EVENMASK) ;  /* try to avoid odd address trap */
  812.     r = (ULONG)(membase & EVENMASK) ;     /* prefer wrong address to death */
  813.     for (i = 0; i < barh; i++)  {
  814.         csum[i] = 0 ;
  815.         }
  816.     for (i = 0; i < barh; i++)  {
  817.         for (a = (ULONG *)r; a < (ULONG *)(r + delta); a++)  {
  818.             csum[i] ^= *a ;
  819.             }
  820.         if (oldcsum[i] != 0)  cell[i] ^= GRNP ;       /* enters with pens  */
  821.         if (csum[i] == oldcsum[i])  cell[i] &= GRNP ; /* all on, condition */
  822.         if (csum[i] == 0)  cell[i] ^= CYNP ;          /* detected clears a */
  823.         if (oldcsum[i] == 0xffffffff) cell[i] = CYNP ;/* pen; at the end a */
  824.         if (csum[i] == 0xffffffff)  cell[i] = GRNP ;  /* logical true sets */
  825.         oldcsum[i] = csum[i] ;                        /* a pen not yet set */
  826.         r += delta ;
  827.         }
  828.     (void) memmometer();
  829. }
  830.  
  831. void updatescreen( wf, membase, memseg )
  832. short wf;
  833. long membase, memseg;
  834.     {
  835.     register long size ;
  836.     register struct MemHeader *hdr ;
  837.     register struct MemChunk *chunk ;
  838.     extern struct ExecBase *SysBase ;
  839.     register long *which ;                /* active memlist chunk pointer */
  840.     register long newlimit ;  /* number of chunks, incl 1 null chunk, + 1 */
  841.     register long newfrags ;  /* number of chunks, incl null chunks, + 1  */
  842.     long newsize ;  /* size of next request for chunkv/sizev memory, + 1  */
  843.     int i, j, k, l ;
  844.     int length ;       /* length is number of chunks to be processed, + 1 */
  845.     BOOL cf, nf ;      /* cf is "chip flag" nf is "null chunk found" flag */
  846.  
  847.     if (memseg == 0) {
  848.         (void) lockout() ;
  849.         return;
  850.         }
  851.     else (void) shake() ;
  852.  
  853.     for (i = 0; i < 3; i++) {
  854.         chip[i] = 0;
  855.         fast[i] = 0;
  856.         }
  857.     for (i = 0; i < frags; i++) {
  858.         chunkv[i] = 0;
  859.         sizev[i] = 0;
  860.         }
  861.     newfrags = 0 ;
  862.     newlimit = 0 ;
  863.     nf = FALSE;
  864.     Forbid() ;
  865.     hdr = (struct MemHeader *) SysBase->MemList.lh_Head ;
  866.     while (hdr->mh_Node.ln_Succ) {
  867.         if (hdr->mh_Attributes & MEMF_CHIP) {
  868.             which = chip ;
  869.             cf = TRUE;
  870.             }
  871.         else {
  872.             which = fast ;
  873.             cf = FALSE;
  874.             }
  875.         if (((cf == TRUE) && (wf == 0)) || ((cf == FALSE) && (wf > 0)))  {
  876.             for (chunk = hdr->mh_First; chunk; chunk = chunk->mc_Next) {
  877.                 if (which[1] < frags)  chunkv[which[1]++] = (unsigned long)chunk ;
  878.                 size = chunk->mc_Bytes ;
  879.                 if (which[2] < frags)  sizev[which[2]++] = (unsigned long)size;
  880.                 *which += size ;
  881.                 if (nf == FALSE)  {
  882.                     newlimit++ ;
  883.                     if (chunkv[newfrags] == NULL)  {
  884.                         nf = TRUE;
  885.                         }
  886.                     }
  887.                 newfrags++ ;
  888.             }
  889.         }
  890.         hdr = (struct MemHeader *)hdr->mh_Node.ln_Succ ;
  891.         }
  892.     Permit() ;
  893.     length = frags ;
  894.     if (newlimit < frags)  length = newlimit ;
  895.     for (i = 0; i < length; i++)  {
  896.         chunkv[i] -= membase;   /* chunkv is now array offset from base   */
  897.         sizev[i] += chunkv[i];  /* and sizev is now address of array top  */
  898.         chunkv[i] = chunkv[i] / memseg;  /* this is the number of pixels  */
  899.         sizev[i] = sizev[i] / memseg;       /* and this is the top pixel  */
  900.         if (chunkv[i] < 0) chunkv[i] = 0 ;  /* we do some bounds checking */
  901.         if (sizev[i] < 0) sizev[i] = 0 ;
  902.         if (chunkv[i] >= barh) chunkv[i] = barh - 1 ;
  903.         if (sizev[i] >= barh) sizev[i] = barh - 1 ;
  904.         if (sizev[i] - chunkv[i] < 0)  sizev[i] = chunkv[i] ;
  905.         j = chunkv[i] ; /* from now on it will be less confusing if */
  906.         k = sizev[i] ;  /* we assign some variables for this stuff  */
  907.         if (sizev[i] - chunkv[i] == 0)  {
  908.             cell[j] &= BLUP ;
  909.             }
  910.         else  {
  911.             for (l = j; l < k; l++)  {
  912.                 cell[l] &= BLKP ;
  913.                 }
  914.             }
  915.         }
  916.     (void) memmometer();
  917.     newsize = frags ;
  918.     while (newsize < newlimit)  {
  919.         newsize += EXTENSION ;
  920.         }
  921.     if (newlimit > frags)  {
  922.         (void) FreeMem(chunkv, (long)(sizeof(long) * frags));
  923.         if ((chunkv = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
  924.                                         MEMF_PUBLIC)) == 0L )  {
  925.             log = log & C2 ;
  926.             }
  927.         (void) FreeMem(sizev, (long)(sizeof(long) * frags));
  928.         if ((sizev = (unsigned long *)AllocMem((long)sizeof(long) * newsize,
  929.                                         MEMF_PUBLIC)) == 0L ) {
  930.             (void) FreeMem(chunkv, (long)(sizeof(long) * newsize));
  931.             log = log & C4 ;
  932.             }
  933.         if (log != SOK)  {
  934.             wrack_sploot() ;
  935.             things_are_cool = FALSE ;
  936.             }
  937.         else frags = newsize ;
  938.         }
  939. }
  940.  
  941. main() {
  942.     static struct IntuiText bodyText0 =
  943.         {BLUP, WHTP, JAM2, 58, 10, NULL, NULL, NULL};
  944.     static struct IntuiText bodyText1 =
  945.         {BLUP, WHTP, JAM2, 42, 20, NULL, NULL, NULL};
  946.     static struct IntuiText bodyText2 =
  947.         {BLUP, WHTP, JAM2, 50, 30, NULL, NULL, NULL};
  948.     static struct IntuiText positiveText =
  949.         {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
  950.     static struct IntuiText negativeText =
  951.         {BLUP, WHTP, JAM2, 7, 3, NULL, NULL, NULL};
  952.     struct IntuiMessage *message;
  953.     ULONG class;
  954.     USHORT code;
  955.     ULONG wakeupbits;
  956.     long syspri;
  957.     char *nptr;
  958.     struct Task *mmtcb;
  959.     char oldpri;
  960.     int t;
  961.     int i;
  962.     USHORT colflags;     /* keeps track of column positions and counts */
  963.     USHORT left;         /* left   column, left edge */
  964.     USHORT middle;       /* middle column, left edge */
  965.     USHORT right;        /* right  column, left edge */
  966.     USHORT barw;         /* width of each mercury column */
  967.     USHORT wf;           /* memmometer window current column number */
  968.     long cmemseg;
  969.     long sfmemseg;
  970.     long fmemseg;
  971.     long membase;
  972.     long memseg;
  973.     long memsize;
  974.  
  975.     bodyText0.IText = (UBYTE *) "WARNING! CRASH POSSIBLE";
  976.     bodyText1.IText = (UBYTE *) "MENU MEMORY SELECTIONS MUST";
  977.     bodyText2.IText = (UBYTE *) "REFERENCE EXISTING MEMORY";
  978.     bodyText0.NextText = &bodyText1;
  979.     bodyText1.NextText = &bodyText2;
  980.     positiveText.IText = (UBYTE *) "Risk It";
  981.     negativeText.IText = (UBYTE *) "Retreat";
  982.  
  983.     log = 0 ;
  984.     if ((cell = (USHORT *)AllocMem((long)sizeof(USHORT) * BARS,
  985.                                         MEMF_PUBLIC)) != 0L ) log = log | S1;
  986.     if ((chunkv = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
  987.                                         MEMF_PUBLIC)) != 0L ) log = log | S2;
  988.     if ((sizev = (ULONG *)AllocMem((long)sizeof(ULONG) * STARTVAL,
  989.                                         MEMF_PUBLIC)) != 0L ) log = log | S4;
  990.     if ((csum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
  991.                                         MEMF_PUBLIC)) != 0L ) log = log | S8;
  992.     if ((oldcsum = (ULONG *)AllocMem((long)sizeof(ULONG) * BARS,
  993.                                         MEMF_PUBLIC)) != 0L ) log = log | SA;
  994.     if (log != SOK)  {
  995.         wrack_sploot() ;
  996.         exit(AARRRGH) ;
  997.         }
  998.     if ((IntuitionBase = (struct IntuitionBase *)OpenLibrary(
  999.             "intuition.library",33L)) != NULL &&
  1000.             (window=OpenWindow(&newwindow)) != NULL)  {
  1001.         if ((GfxBase = (struct GfxBase *)OpenLibrary(
  1002.                 "graphics.library", 0L)) != NULL)  { 
  1003.             (void) initmenus();
  1004.             /* rp = window->RPort ; */
  1005.             inittimer();
  1006.             wf = 0;
  1007.             mmode = FALSE ;
  1008.             mode = FRAGS ;
  1009.             delayval = p_rate ;
  1010.             priority = p_priority ;
  1011.             if (priority > 0)  priority = 0 ;
  1012.             lastpri = priority ;
  1013.             syspri = priority ;
  1014.             nptr = NULL ;
  1015.             mmtcb = FindTask( nptr ) ;
  1016.             oldpri = SetTaskPri( mmtcb, syspri ) ;
  1017.             cmemsize = p_chip << 10 ;
  1018.             cmembase = p_chipa << 10 ;
  1019.             sfmemsize = p_sf << 10 ;
  1020.             sfmembase = p_sfa << 10 ;
  1021.             if (p_fast >= 256)  fmemsize = p_fast << 10 ;
  1022.             else fmemsize = p_fast << 20 ;
  1023.             if (p_fasta <= 0)  fmembase = 0x8000000 - ((-1 * p_fasta) << 20) ;
  1024.             else fmembase = p_fasta << 20 ;
  1025.             while (things_are_cool == TRUE) {
  1026.                 if (chgflag != 0)  {
  1027.                     chgflag = 0 ;
  1028.                     colflags = 0 ;
  1029.                     if (cmemsize != 0)  colflags = colflags | (1 << 0) ;
  1030.                     if (sfmemsize != 0)  colflags = colflags | (1 << 1) ;
  1031.                     if (fmemsize != 0)  colflags = colflags | (1 << 2) ;
  1032.                     switch ( colflags ) {
  1033.                         case 0:
  1034.                         barw = (WINW - (2 * BORDER)) - 1 ;
  1035.                         left = LEFT ;
  1036.                         middle = 0 ;
  1037.                         right = 0 ;
  1038.                         f_text.FrontPen = ORNP ;
  1039.                         break ;
  1040.  
  1041.                         case 1:
  1042.                         barw = (WINW - (2 * BORDER)) - 1 ;
  1043.                         left = LEFT ;
  1044.                         middle = 0 ;
  1045.                         right = 0 ;
  1046.                         f_text.FrontPen = BLUP ;
  1047.                         break ;
  1048.  
  1049.                         case 2:
  1050.                         barw = (WINW - (2 * BORDER)) - 1 ;
  1051.                         left = 0 ;
  1052.                         middle = LEFT ;
  1053.                         right = 0 ;
  1054.                         f_text.FrontPen = CYNP ;
  1055.                         break ;
  1056.  
  1057.                         case 3:
  1058.                         barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  1059.                         left = LEFT ;
  1060.                         middle = (left + barw + 1) ;
  1061.                         right = 0 ;
  1062.                         f_text.FrontPen = BLUP ;
  1063.                         break ;
  1064.  
  1065.                         case 4:
  1066.                         barw = (WINW - (2 * BORDER)) - 1 ;
  1067.                         left = 0 ;
  1068.                         middle = 0;
  1069.                         right = LEFT ;
  1070.                         f_text.FrontPen = YELP ;
  1071.                         break ;
  1072.  
  1073.                         case 5:
  1074.                         barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  1075.                         left = LEFT ;
  1076.                         middle = 0 ;
  1077.                         right = (left + barw + 1) ;
  1078.                         f_text.FrontPen = CYNP ;
  1079.                         break ;
  1080.  
  1081.                         case 6:
  1082.                         barw = ((WINW - (2 * BORDER)) / 2 ) - 1 ;
  1083.                         left = 0 ;
  1084.                         middle = LEFT ;
  1085.                         right = (middle + barw + 1) ;
  1086.                         f_text.FrontPen = YELP ;
  1087.                         break ;
  1088.  
  1089.                         case 7:
  1090.                         barw = ((WINW - (2 * BORDER)) / 3 ) - 1 ;
  1091.                         left = LEFT ;
  1092.                         middle = (left + barw + 1) ;
  1093.                         right = (middle + barw + 1) ;
  1094.                         f_text.FrontPen = BLUP ;
  1095.                         break ;
  1096.                         }  /* end of switch ( colflags ) */
  1097.                     }  /* end of if ( chgflag ) */
  1098.                 cmemseg = cmemsize / barh ;
  1099.                 sfmemseg = sfmemsize / barh ;
  1100.                 fmemseg = fmemsize / barh ;
  1101.                 if (mmode == TRUE && ((sfmemsize != 0) ||
  1102.                                       (fmemsize != 0)))  {
  1103.                     /* Keep your eyes open here.  If we get a negative    */
  1104.                     /* response from the requester, that means either the */
  1105.                     /* user retreated, or a no-requester function such as */
  1106.                     /* noreq or KillReq has selected the negative option. */
  1107.                     /* If such functions select the positive option they  */
  1108.                     /* force acceptance of the crash risk for Warps mode. */
  1109.  
  1110.                     mode = AutoRequest(window, &bodyText0, &positiveText,
  1111.                                &negativeText, 0L, 0L, 319L, 79L) ;
  1112.                     if (mode == FALSE)  {      /* user Retreat selection  */
  1113.                         sfmemseg = 0 ;         /* results in execution of */
  1114.                         sfmemsize = 0 ;        /* this code segment which */
  1115.                         fmemseg = 0 ;          /* resets to safer values  */
  1116.                         fmemsize = 0 ;         /* resets to safer values  */
  1117.                         }
  1118.                     }
  1119.                 switch ( wf ) {
  1120.                     case 0:
  1121.                     xl = left ;
  1122.                     membase = cmembase ;
  1123.                     memseg = cmemseg ;
  1124.                     memsize = cmemsize ;
  1125.                     break;
  1126.  
  1127.                     case 1:
  1128.                     xl = middle ;
  1129.                     membase = sfmembase ;
  1130.                     memseg = sfmemseg ;
  1131.                     memsize = sfmemsize ;
  1132.                     break;
  1133.  
  1134.                     case 2:
  1135.                     xl = right ;
  1136.                     membase = fmembase ;
  1137.                     memseg = fmemseg ;
  1138.                     memsize = fmemsize ;
  1139.                     break;
  1140.                     }  /* end of switch ( wf ) */
  1141.                 xr = xl + barw ;
  1142.                 if (mmode == TRUE)  {
  1143.                     mode = WARPS ;
  1144.                     mmode = FALSE ;
  1145.                     }
  1146.                 if (xl != 0)  {
  1147.                     if (intsig == TRUE)  {
  1148.                         handle_NEWSIZE() ;
  1149.                         }
  1150.                     if (mode == WARPS)  {
  1151.                         (void) updatewarps( wf, membase, memseg ) ;
  1152.                         e_text.FrontPen = YELP ;
  1153.                         }
  1154.                     if (mode == FRAGS)  {
  1155.                         (void) updatescreen( wf, membase, memseg ) ;
  1156.                         e_text.FrontPen = BLUP ;
  1157.                         }
  1158.                     }
  1159.                 if (syspri != priority)  {
  1160.                     syspri = priority ;
  1161.                     nptr = NULL;
  1162.                     mmtcb = FindTask( nptr ) ;
  1163.                     oldpri = SetTaskPri( mmtcb, syspri ) ;
  1164.                     }
  1165.                 if (wf == 2)  {
  1166.                     PrintIText(window->RPort,&f_text,RTEXT,0L) ;
  1167.                     while ( ticker > 0 )  {
  1168.                         wakeupbits = Wait(timerbit) ;
  1169.                         if (wakeupbits & timerbit)  {
  1170.                             GetMsg(timerport);
  1171.                             SetTimer(0L, TMARK, timermsg);
  1172.                             }
  1173.                         /* quick like, go see if the user wants anything */
  1174.                         (void) handle_MESSAGES() ;
  1175.                         ticker-- ;
  1176.                         }
  1177.                     ticker = delayval * TICKIES ;
  1178.                     }
  1179.                 wf++ ;
  1180.                 if (wf >= 3)  wf = 0 ;
  1181.                 if (intsig == TRUE)  {
  1182.                     handle_NEWSIZE() ;
  1183.                     }
  1184.                 } /* end of while ( things_are_cool) */
  1185.  
  1186.             if (timerport) {
  1187.                 Wait(timerbit);
  1188.                 GetMsg(timerport);
  1189.                 CloseDevice(timermsg);
  1190.                 DeleteStdIO(timermsg);
  1191.                 DeletePort(timerport);
  1192.                 }
  1193.  
  1194.             if (GfxBase)    CloseLibrary(GfxBase) ;
  1195.             }
  1196.         if (window)         CloseWindow(window) ;
  1197.         if (IntuitionBase)  CloseLibrary(IntuitionBase) ;
  1198.         }
  1199.     wrack_sploot() ;
  1200. }
  1201.  
  1202. _cli_parse() {}
  1203. _wb_parse() {}
  1204.